-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for libvips in addition to ImageMagick #30090
Conversation
407560d
to
b2407c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Github actions will need to install libvips42
instead of imagemagick
.
There are probably some ImageMagick related files to remove, for example config/imagemagick
.
The Docker image will also need to be changed to install vips, @vmstan started to work on it. Maybe you can update it in this PR to simply install libvips42
in place of imagemagick
, and @vmstan can open another PR later to get it installed better (because the current Debian package enabled far too many formats for our usage).
We will also need to take great care in the upgrade instructions to tell people that they need to install VIPS now (and uninstall IM?). This will also be an issue with people running on nightly. The alternative is to support both IM and VIPS for 4.3, with a config option to enable VIPS, show a deprecation warning with IM is used, and remove IM support in 4.4, but I do not know if this is worth it.
It is also probably a good idea to call Untrusted operations can be seen with |
4e72551
to
f29cce2
Compare
9bd1761
to
79559f3
Compare
This pull request has merge conflicts that must be resolved before it can be merged. |
Worth adding libheif? |
It's included by the libvips42 package. |
I’ve been running this PR for the last 20 hours on vmst.io and it’s been largely successful. I have had no user reported issues uploading and processing image content, but noticed a few entries in Sidekiq dead queue triggered by a few remote posts.
|
I've run into an issue where uploading a PNG file that exceeds the allowed dimensions/megapixels results in an error of Uploading a file that is exactly 2160x3840 works, but a file that is 2161x3842 will result in the above error. In both cases the file is roughly 4.6 MB in size. So not only is the wrong type of error being triggered, it doesn't seem like any error should be triggered if the file was rescaled by vips. I do not see this issue with JPG or HEIF files. |
@vmstan As a switch to libvips supposedly allows WebP and AVIF files to be rendered in link previews (closing #27370 and #14983, and probably many more) do you see that many of the issues listed here are resolved? |
I test posted all of the links shared in that comment and they looked the same on my instance running with vips as they do on mastodon.online running ImageMagick and similar build of 4.3. |
OK, that's odd. As I've already bug spammed this ticket enough and this is a libvips implementation ticket let's get to the bottom of the issue using ticket #14983 and consider using ticket #27370 as a potential stopgap until the system accepts WebP and AVIF. Once libvips has properly landed I can be more helpful with troubleshooting. |
This condition should never happen, but if it does, an exception is better than a segfault
1ab7856
to
d729ac5
Compare
I don't think this PR changes that significantly, and we want to avoid large file sizes in general. But if you have an example file, I can have a look at what the quality ends up like. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not 100% sure about the color extraction code, but if my understanding of it is correct, the worst case scenario is rare and just results in suboptimal color selection, not any functional error.
I will continue investigating this, but this should not block a merge.
webp's 90 quality generally has significantly worse compression artifacts than others at 90 quality as mastodon uses the same quality for all, this is quite an issue for WEBP (a few test images, encoded with imagemagik, same arguments as this particular scene is probably one of the worst cases for WEBP compression, but it's not exclusive to this case, and it's not that uncommon https://bin.blobfox.coffee/file/e7WGQe/mastodon-quality-test-image-reference.png https://bin.blobfox.coffee/file/dGZK0b/mastodon-quality-test-image-lossless.webp At the moment mastodon will reencode that lossless WEBP into the image below, so if you want to upload something losslessly you will have to upload as a usually less compression efficient PNG, wasting your time, compute, and storage https://bin.blobfox.coffee/file/dw81re/mastodon-quality-test-image-default.webp https://bin.blobfox.coffee/file/ejNxze/mastodon-quality-test-image.jpg https://bin.blobfox.coffee/file/aOo3Ya/mastodon-quality-test-image-jpeg-like.webp i would guess that checking which method an image in a codec capable of both lossless and lossy modes uses would reduce media storage usage, due to the above, and increasing the quality of lossy WEBP to be more visually on par with JPEG would help with getting people to use the more efficient codec, rather than being appalled at their image being immensely compressed. uhh, TLDR: lossless images in lossy codecs should be treated like PNG (WEBP at least stores metadata on whether it is or isn't lossless), and WEBP's quality 90 produces much worse looking images than JPEG quality 90 sorry if this is an excessive reply, lol. /gen |
I realize this is a month old and merged already, but curious on the added CI config here -- is the only difference between the newly added VIPS section and the regular spec run -- a) the addition of the env var to opt-in to vips, b) running just the paperclip_processing subset of specs on the vips section? If so ... I wonder if we could just tack this on to the end of the other runs (in ruby version matrix)? Those specs take ~30s, but we're tacking on another ~1min per ruby version for the setup surrounding them. |
Yes, those are about the only changes. I suppose moving them to an additional step in the regular tasks may make sense. |
Looked a bit more and realized that the VIPS job also switched the runner to I also thought about this a bit more and it might not make sense to tack on more tasks to the end of what is already the longest task ... even though we are repeating the ruby setup, the vips task woul be done before the main long rspec run. So tacking it would reduce the total CI minutes in a given day (fewer over ruby setup runs), but not shorten the length of the run for a single PR, if that makes sense. May re-visit this when GH promotes ubuntu 24 to be the |
Libvips can be used instead of ImageMagick with
MASTODON_USE_LIBVIPS=true
. Enabled by default in the Docker image.Fixes MAS-223